<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>17-电话号码的字母组合</title>
	</head>
	<body>
		<script type="text/javascript">
			/**
			 * @param {string} digits
			 * @return {string[]}
			 * 淦，最后还是整错了，题理解错了，全弄成两位的笛卡尔积了唉，不想弄了，题解都是回溯又看不懂
			 */
			var letterCombinations = function(digits) {
			    let arr = [["a","b","c"],["d","e","f"],["g","h","i"],
							["j","k","l"],["m","n","o"],["p","q","r","s"],
							["t","u","v"],["w","x","y","z"]]
			    let res = []
			    let Descartes = function(a,b){ //传两个数组进行笛卡尔乘积
			        for(let i = 0;i<a.length;i++){
			            for(let j = 0;j<b.length;j++){
			                res.push(a[i]+b[j]);
			            }
			        }
			    }
				let Descarte = function(arr){ //传数字进行笛卡尔乘积 返回二维数组
					let res = []
				    for(let i = 0;i<arr.length;i++){
				        for(let j = i+1;j<arr.length;j++){
							res.push([arr[i],arr[j]]);
						}
				    }
					return res;
				}
			    let data = Array.from(digits); //拆分成字符串数组
			    // let data = arr.splice('');
			    data = data.map((val)=>{
			        return parseInt(val);
			    })  //转成数字数组
				console.log('data',data)
			    if(data.length < 1) {return res;}
			    else if(data.length == 1) {return arr[data[0]-2];}
			    else{
			        let count =Descarte(data);//计算组合
					// console.log('count',count)
			        for(let i = 0; i<count.length;i++){
			            Descartes(arr[count[i][0]-2],arr[count[i][1]-2]);
			        }
			    }
				// console.log(res)
			    return res;
			};
			letterCombinations('2356');
		</script>
	</body>
</html>
